package com.baidu.shopping.dao;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import com.baidu.shopping.pojo.Cart;

@Repository
public class ShoppingDaoImpl implements ShoppingDaoI {
	
	@Autowired
	private MongoTemplate mongoTemplate;

	@Override
	public boolean addAppIntoCart(Cart cart) {
		
		try {
			mongoTemplate.save(cart, "cart");
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public Cart getCartById(String ip) {
		
		return mongoTemplate.findOne(new Query(Criteria.where("_id").is(ip)), Cart.class, "cart");
	}





}
